package com.hmall.item.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
//import com.hmall.item.pojo.ItemDoc;
//import com.hmall.item.pojo.PageDTO;
//import com.hmall.item.pojo.QueryDto;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.bouncycastle.asn1.x500.style.RFC4519Style.cn;
import static org.bouncycastle.asn1.x500.style.RFC4519Style.st;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {
    @Autowired
    private ItemMapper itemMapper;

    @Override
    public PageDTO list(Integer pageNum, Integer pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<Item> list = itemMapper.getbyPage();
//        return (PageDTO) list;

        Page<Item> paged = lambdaQuery().orderByDesc(Item::getCreateTime).page(Page.of(pageNum, pageSize));
        System.out.println(new PageDTO<>(paged.getTotal(), paged.getRecords()));
        return new PageDTO<>(paged.getTotal(), paged.getRecords());
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        itemMapper.qy(id,status);
    }

    @Override
    public boolean removeById(Serializable id) {
        //判断status是否为2，不为2就放行
        Item item = getById(id);
        if (item.getStatus()!=2){
            return false;
        }
        return super.removeById(id);
    }
}
